import os
from langchain_community.chat_models import ChatZhipuAI 
from dotenv import load_dotenv, find_dotenv
from langchain_core.output_parsers import StrOutputParser

_ = load_dotenv(find_dotenv())

api_key = os.environ.get('ZHIPU_API_KEY')
if api_key is None:
    raise ValueError("API Key is not set in the .env file")

model = os.environ.get('model')
if model is None:
    raise ValueError("model is not set in the .env file")

llm = ChatZhipuAI(api_key=api_key,
                  model=model,
                  temperature=0.9,              
                )

response = llm.invoke("讲一个笑话。")
strResult = StrOutputParser()
result= strResult.invoke(response)
print(result)
